#include <iostream>
#include <string>
using namespace std;
#define N 100
int a[N][N], b[N][N], n, m, m_, n_;
string M;
void set()
{
	int c, i, j;
	for (c = 0; M[c] != '\0'; c++)
	{
		switch (M[c])
		{
		case 'A':
			for (j = 0; j < m; j++)
			{
				for (i = n - 1; i >= 0; i--)
				{
					b[j][i] = a[i][j];
				}
			}
			break;
		case 'B':
			for (j = m - 1; j >= 0; j--)
			{
				for (i = 0; i < m; i++)
				{
					b[j][i] = a[i][j];
				}
			}
			break;
		case 'C':
			for (i = m - 1; i >= 0; i--)
			{
				for (j = 0; j < m; j++)
				{
					b[i][j] = a[i][j];
				}
			}
			break;
		case 'D':
			for (i = 0; i < n; i++)
			{
				for (j = m - 1; j >= 0; j--)
				{
					b[i][j] = a[i][j];
				}
			}
			break;
		}
	}
}
int main()
{
	int i, j, k;
	cin >> n >> m;
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < m; j++)
		{
			cin >> a[i][j];
		}
	}
	cin >> M;
	set();
	for (i = 0; i < m; i++)
	{
		for (j = 0; j < n; j++)
		{
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}